package cn.yesway.common.utils;

import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 对hibernate连接数据库的用户名 和 密码进行加密处理
 * @author chencq
 *
 */
public class MyConfigurer extends PropertyPlaceholderConfigurer {

	protected Logger logger = LoggerFactory.getLogger(MyConfigurer.class);
	
	protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)throws BeansException {

		String keyWords = "cn.yesway";// 加密密匙
		DES des = new DES(keyWords);
		
		logger.info("MyConfigurer  start");
		String password = props.getProperty("yconnect.jdbc.username");
		String username =props.getProperty("yconnect.jdbc.password");
		if (password != null) {
			props.setProperty("yconnect.jdbc.username", des.decypt(username));
			props.setProperty("yconnect.jdbc.password", des.decypt(password));
		}
		logger.info("MyConfigurer end!---->"+des.decypt(password));
		super.processProperties(beanFactory, props);
	}
}
